package cn.itcast.web.controller;

import cn.itcast.domain.system.User;
import cn.itcast.service.system.UserService;
import org.apache.shiro.web.session.HttpServletSession;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public abstract class BaseController {
    //注入servletApi,这样就可以在控制器中直接使用
    @Autowired
    protected HttpServletRequest request;
    @Autowired(required = false)//response爆红添加这个即可
    protected HttpServletResponse response;  //如果出现编译报错不用管,idea的问题
    @Autowired
    protected HttpSession session;

    /*
    * 获取登录用户的企业id
    * */
    public String getLoginCompanyId(){
        return getLoginUser().getCompanyId();
    }

    /*
    *  获取登录用户的企业名称
    *  */
    public String getLoginCompanyName(){
        return getLoginUser().getCompanyName();
    }

    //创建获取登录用户的方法
    public User getLoginUser(){
        return (User) session.getAttribute("loginUser");

    }
}
